import axios from "axios";
// import store from "@/store";

const service = axios.create({
  // 请求超时时间
  timeout: 10000
});

// 添加请求拦截器
service.interceptors.request.use(
  config => {
    let _this = this;
    // let uniacid = store.state.user.uniacid ? store.state.user.uniacid : 0;
    // let userid = store.state.user.userInfo.id
    //   ? store.state.user.userInfo.id
    //   : 0;
    // let manager = store.state.user.userInfo.manager
    //   ? store.state.user.userInfo.manager
    //   : 0;
    // let userInfo = store.state.user.userInfo;
    var a = 1;
    if (a == 1) {
      console.log("来到了拦截器");
      config.headers.Authorization = 'Up-Userid';
      config.headers["Up-Userid"] = 1;
      // config.headers["Access-Control-Allow-Origin"] = "*";
    } else {
      _this.$router.push("/");
    }
    return config;
  },
  err => {
    console.log(err);
  }
);

//
service.interceptors.response.use(
  response => {
    let res = {};
    // if{} 这里可以判断转台吗跳转到404等页面
    res.status = response.status;
    res.data = response.data;
    return res;
  },
  err => console.log(err)
);

export default service;
